/**
 * Created by ajhin on 2/25/2015.
 */
package com.societyGames.grid
{
import flash.display.DisplayObject;

public class GridObject
{
  private var _displayObject:DisplayObject;
  private var _grid:Grid;
  private var _gridX:Number;
  private var _gridY:Number;

  public function GridObject(grid:Grid)
  {
    _grid = grid;
  }

  public function get gridX():Number
  {
    return _gridX;
  }

  public function set gridX(value:Number):void
  {
    if (value != _gridX)
    {
      _gridX = value;
      _displayObject.x = _grid.xFromGridX(_gridX);
    }
  }

  public function get gridY():Number
  {
    return _gridY;
  }

  public function set gridY(value:Number):void
  {
    if (value != _gridY)
    {
      _gridY = value;
      _displayObject.y = _grid.yFromGridY(_gridY);
    }
  }

  public function set displayObject(value:DisplayObject):void
  {
    if (value != null)
    {
      value.x = _grid.xFromGridX(_gridX);
      value.y = _grid.yFromGridY(_gridY);
    }
    _grid.replaceDisplayObject(_displayObject, value);
    _displayObject = value;
  }

  public function get displayObject():DisplayObject
  {
    return _displayObject;
  }
}
}
